<template>
	<view class="wrap">
		<view class="top"></view>
		<view class="content">
			<view class="title">欢迎登录牛逼书屋</view>
			<input class="u-border-bottom" type="text" v-model="email" placeholder="请输入邮箱" />
			<input class="u-border-bottom" type="password" v-model="password" placeholder="请输入密码" />
			<button @tap="submit" :style="[inputStyle]" class="getCaptcha">登录</button>
			<view class="alternative">
				<view class="password"@tap="goRegister">注册</view>
				<view class="issue">忘记密码</view>
			</view>
		</view>
	</view>	
</template>

<script>
export default {
	data() {
		return {
			email: '',
			password:''
		}
	},
	computed: {
		inputStyle() {
			let style = {};
			if(this.$u.test.email(this.email) && this.password) {
				style.color = "#fff";
				style.backgroundColor = this.$u.color['warning'];
			}
			return style;
		}
	},
	methods: {
		async submit() {
			//验证失败直接返回
			if(!this.$u.test.email(this.email) || !this.password) return
			const params = {
				email:this.email,
				password:this.password
			}
			//登录请求
			const loginRes = await this.$u.api.authLogin(params)
			
			//存储token
			const {access_token} = loginRes;
			this.$u.vuex("vuex_token",access_token)
			
			this.$u.utils.updateUserInfo()
			
			//返回源页面
			const source_page = uni.getStorageSync("source_page") || "pages/index/index"
			this.$u.route({
				type:"reLaunch",
				url:source_page
			})
			
		},
		goRegister(){
			//前往注册页
			this.$u.route({
				type:"reLaunch",
				url:"pages/auth/register"
			})
		}
		
	}
};
</script>

<style lang="scss" scoped>
.u-border-bottom{
	padding: 30rpx !important;
	margin-bottom: 20rpx !important;
}	
.wrap {
	font-size: 28rpx;
	.content {
		width: 600rpx;
		margin: 80rpx auto 0;

		.title {
			text-align: left;
			font-size: 60rpx;
			font-weight: 500;
			margin-bottom: 100rpx;
		}
		input {
			text-align: left;
			margin-bottom: 10rpx;
			padding-bottom: 6rpx;
		}
		.tips {
			color: $u-type-info;
			margin-bottom: 60rpx;
			margin-top: 8rpx;
		}
		.getCaptcha {
			background-color: rgb(253, 243, 208);
			color: $u-tips-color;
			border: none;
			font-size: 30rpx;
			padding: 12rpx 0;
			
			&::after {
				border: none;
			}
		}
		.alternative {
			color: $u-type-primary-disabled;
			font-weight: 600;
			font-size: 30rpx;
			display: flex;
			justify-content: space-between;
			margin-top: 30rpx;
			
		}
	}

}

</style>
